
/**
 * Created by Mj on 2017/9/5.
 * 公共类
 */
var Util = {
	//get
	get: function(url, data, callback) {
			$.ajax({
				url: url,
				type: "get",
				data: data,
				dataType: "json",
				beforeSend: function() {
					//数据正在加载
				},
				success: function(res) {
					//加载成功
					console.log(res);
					callback(res);
				},
				error: function() {
					//加载失败
				}
			});
	},
	//post
	post: function(url, data, callback) {
			data = JSON.stringify(data),
			$.ajax({
				url: url,
				data: data,
				type: 'post',
				dataType: 'json',
				contentType: 'application/json; charset=utf-8',
				beforeSend: function() {
					//数据正在加载
				},
				success: function(res) {
					//加载成功
					callback(res);
				},
				error: function() {
					//加载失败
				}
			});
	},
	//获取url参数
	GetQueryString: function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if(r != null)
			return unescape(r[2]);
		return null;
	},

	//时间戳
	UnixToDate: function(unixTime, isFull, timeZone) {
		if(typeof(timeZone) == 'number') {
			unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
		}
		var time = new Date(unixTime * 1000);
		var ymdhis = "";
		ymdhis += time.getUTCFullYear() + "-";
		ymdhis += (time.getUTCMonth() + 1) + "-";
		ymdhis += time.getUTCDate();
		if(isFull === true) {
			ymdhis += " " + time.getUTCHours() + ":";
			ymdhis += time.getUTCMinutes() + ":";
			ymdhis += time.getUTCSeconds();
		}
		return ymdhis;
	},
	// 跳转
	jump: function(url) {
		window.location.href = url;
	},
	//返回的顶部
	Pinterest: function(callback) {
		var hasmore = true
		$(window).scroll(function() {
			var down = $(document).height() - $(document).scrollTop() - $(window).height();
			if(down <= 50 && hasmore == true) {
				hasmore = false;
				if(callback)
					callback();

			}
			if(down > 50) {
				hasmore = true
			}
		})
	}
}


//获取数据渲染数据
var Public = {
	gateway:function(data, callback) {//获取支付列表
		Util.post(API.gateway, data, function(res) {
			if(res.code == 200) {
				var imgArr = new Array();
				for(var i=0; i<res.data.length; i++){
					imgArr[i] = new Array();
					imgArr[i]= res.data[i].icon.split(',');
					res.data[i].icon = imgArr[i];
				}
				if(callback)
					callback(res)
			} else {
				
			}
		});
	},
	ChangePayByHome:function(data, callback) {//#降低费率页面#切换支付方式拉取列表
		Util.post(API.gateway, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				
			}
		});
	},
	ChangePayByRece:function(data, callback) {//#收款页面#支付方式拉取列表
		Util.post(API.gateway, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				var imgArr = new Array();
				for(var i=0; i<res.data.length; i++){
					imgArr[i] = new Array();
					imgArr[i]= res.data[i].icon.split(',');
					res.data[i].icon = imgArr[i];
				}
				if(callback)
					callback(res)
			} else {
				
			}
		});
	},
	Confirm:function(data, callback) {//#收款页面#确认按钮拉取银行等信息
		Util.post(API.gateway, data, function(res) {
			console.log(res);
			if(res.code == 200) {
				if(callback)
					callback(res)
			} else {
				
			}
		});
	},
}


//页面交互,dom操作
var Vim = {
	/**
	 * 降低费率 index.html
	 * 
	 * */
	//切换支付方式拉取列表
	ChangePayByHome: function(that){
		var userId = Util.GetQueryString('userid');//获取url传递的userid
		var payType = $(that).data('paytype');
		Public.ChangePayByHome({
			method:"product.rate.list",
			userId:userId,
			payTradeWay:payType,
			productType:0,
			version:"1.0.2"
		},function(res){
			html = template.render("template_Receivablesboxlist", res);
			$('#Receivablesboxlist').html(html);
		});
	},
	/**
	 * 降低费率 mypassageway.html
	 * 
	 * */
	//切换支付方式拉取列表
	ChangePayByMypassageway:function(that){
		var userId = Util.GetQueryString('userid');//获取url传递的userid
		var payType = parseInt($(that).data('paytype'));
			Public.ChangePayByHome({
				method:"channel.have.search",
				userId:userId,
				payTradeWay:payType,
				productType:0,
				version:"1.0.2"
		},function(res){
			html = template.render("template_Receivablesboxlist", res);
			$('#Receivablesboxlist').html(html);
			console.log(res);
		});
	},
	
}
